package com.zqs.controller;

import com.zqs.entity.Product;
import com.zqs.service.ProductService;
import com.zqs.utils.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 汽车商品页
 */
@CrossOrigin
@RestController
@RequestMapping("products")
public class ProductController extends BaseController{

    @Autowired
    private ProductService productService;

    // 查询汽车类别下的商品 query{cid,bid}
    @GetMapping("get_category_list")
    public JsonResult<List<Product>> getCategoryList(Integer cid,Integer bid){
        List<Product> datalist = productService.categoryList(cid, bid);
        return new JsonResult<>(OK,datalist);
    }

    // 汽车详情  query{pid}
    @GetMapping("car_detail")
    public JsonResult<Product> carDetail(Integer pid){
        Product data = productService.carDetail(pid);
        return new JsonResult<>(OK,data);
    }

    // 根据价格降序 
    @GetMapping("findAllByPriceDesc")
    public JsonResult<List<Product>> findAllByPriceDesc(){
        List<Product> datalist = productService.findAllByPriceDesc();
        return new JsonResult<>(OK,datalist);
    }

    // 根据价格升序
    @GetMapping("findAllByPriceAsc")
    public JsonResult<List<Product>> findAllByPriceAsc(){
        List<Product> datalist = productService.findAllByPriceAsc();
        return new JsonResult<>(OK,datalist);
    }

    // 根据时间降序
    @GetMapping("findAllByTime")
    public JsonResult<List<Product>> findAllByTime(){
        List<Product> datalist = productService.findAllByTime();
        return new JsonResult<>(OK,datalist);
    }

    // 查找全部商品
    @GetMapping("findAll")
    public JsonResult<List<Product>> findAll(){
        List<Product> datalist = productService.findAll();
        return new JsonResult<>(OK,datalist);
    }

    // 模糊查询
    @GetMapping("findByProductName")
    public JsonResult<List<Product>> findByProductName(String name){
        List<Product> datalist = productService.findByProductName(name);
        return new JsonResult<>(OK,datalist);
    }
}
